<%--
  Created by IntelliJ IDEA.
  User: Andy
  Date: 2021.3.24
  Time: 14:34
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<base href="http://${pageContext.request.serverName}:${pageContext.request.serverPort}/"/>
<script type="text/javascript" src="jquery/jquery-2.1.1.min.js"></script>
<script type="text/javascript" src="layer/layer.js"></script>
<script type="text/javascript">
    $(function () {
        window.location.href = "/admin/to/login/page.html";
        $("#btn1").click(function () {
            $.ajax({
                "url": "send/array/one.html",       // 请求目标资源的地址
                "type": "post",                 // 请求方式
                "data": {                       // 要发送的请求参数
                    "array": [5,8,12]
                },
                "dataType": "text",             // 如何对待服务器端返回的数据
                "success": function (response) {    // 服务器成功处理请求后的回调函数
                    alert(response);
                },
                "error":function (response) {       // 服务器失败处理请求后的回调函数
                    alert(response);
                }
            })
        })
        $("#btn2").click(function () {
            $.ajax({
                "url": "send/array/two.html",       // 请求目标资源的地址
                "type": "post",                 // 请求方式
                "data": {                       // 要发送的请求参数
                    "array[0]": 5,
                    "array[1]": 8,
                    "array[2]": 12
                },
                "dataType": "text",             // 如何对待服务器端返回的数据
                "success": function (response) {    // 服务器成功处理请求后的回调函数
                    alert(response);
                },
                "error":function (response) {       // 服务器失败处理请求后的回调函数
                    alert(response);
                }
            })
        })
        $('#btn3').click(function () {
            var array = [5, 8, 12];
            var requestBody = JSON.stringify(array);
            $.ajax({
                url: 'send/array/three.html',
                type: 'post',
                data: requestBody,
                contentType: 'application/json;charset=utf-8',
                dataType: 'text',
                success: function (data) {
                    alert(data)
                },
                error: function (error) {
                    alert(error)
                }
            });
        })
        $('#btn4').click(function () {
            // 准备要发送的数据
            var student = {
                "stuId" : 5,
                "stuName" : "Tom",
                "address" : {
                    "province" : "广东",
                    "city" : "深圳",
                    "street" : "邯郸",
                },
                "subjectList" : [
                    {
                        "subjectName":"JavaSE",
                        "subjectScore":"100"
                    },{
                        "subjectName":"SSM",
                        "subjectScore":"99"
                    }
                ],
                "map":{
                    "k1":"v1",
                    "k2":"v2"
                }
            }
            var requestBody = JSON.stringify(student);

            $.ajax({
                url: '/send/compose/object.json',
                type: 'post',
                data: requestBody,
                contentType: 'application/json;charset=utf-8',
                dataType: 'json',
                success: function (data) {
                    console.log(data);
                    // alert(data);
                },
                error: function (error) {
                    console.log(error);
                }
            });
        });
        $("#btns").click(function () {
            layer.msg("Layer的弹窗")
        })
    })
</script>
<html>
<head>
    <title>Insert title here</title>
</head>
<body>
    <a href="/test/ssm.html">测试SSM整合环境</a>
    <button id="btn1">Semd [5,8,12]</button>
    <button id="btn2">Semd [5,8,12]</button>
    <button id="btn3">Semd [5,8,12]</button>
    <button id="btn4">Semd Compose Object</button>

    <br/>
    <button id="btns">点我弹框</button>
</body>
</html>
